<?php
class contIndex extends coreController
{
    protected $template = 'sample1';
    
    public function index()
    {
        Ui(':uipackBootstrap')->plugin('Validator', array(
        	'form' => 'login_form'
        ));
        
        $this->js('default');
        
        if (s()->get('user_id') !== false) {
            $this->setCustom(array(
                'logged_msg' => '<li><a href="/index.php?controller=index&method=logout" style="color:#F30">LOGOUT</a></li>'
            ));
        }
        
        $aRow = $this->model('Example')->get();
        
        $this->view('main', array(
            'article_list' => $aRow
        ));
    }
    
    public function login()
    {
        $this->setTemplate(null);
        
        $sId = r()->getParam('user_id', 'post');
        $sPass = r()->getParam('user_passwd', 'post');
        
        if ($this->model('Example')->isLogin($sId, $sPass) === true) {
            s()->set('user_id', $sId);
            echo utilJavascript::getInstance()->locationReplace('/index.php');
        } else {
            echo utilJavascript::getInstance()->historyBack('로그인 정보가 올바르지 않습니다.');
        }
    }
    
    public function logout()
    {
        $this->setTemplate(null);
        
        s()->set('user_id');
        
        echo utilJavascript::getInstance()->locationReplace('/index.php');
    }
}